local skel = fk.CreateSkill {
  name = "#counter_trigger",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "control",
  priority = 0.001,
  can_trigger = function(self, event, target, player, data)
    local tag = player.room:getTag("counter_record") or Util.DummyTable
    return target ~= player and table.find(player:getCardIds("j"), function (id)
      local card = player:getVirtualEquip(id) or Fk:getCardById(id)
      return card.name == "counter" and tag[tostring(id)] == data.card.trueName
    end)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#counter-ask:"..target.id.."::"..data.card:toLogString() })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local gender = player.gender == General.Male and "male" or "female"
    room:broadcastPlaySound("./packages/moepack/audio/card/".. gender .. "/counter")
    room:doIndicate(player, {target})
    data.toCard = nil
    data.nullifiedTargets = table.simpleClone(player.room.players)
    local tag = player.room:getTag("counter_record") or Util.DummyTable
    local cid = table.find(player:getCardIds("j"), function (id)
      local card = player:getVirtualEquip(id) or Fk:getCardById(id)
      return card.name == "counter" and tag[tostring(id)] == data.card.trueName
    end)
    if cid then
      tag[tostring(cid)] = nil
      room:setTag("counter_record", tag)
      room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name)
    end
  end,
})

Fk:loadTranslationTable{
  ["#counter_trigger"] = "反制",
  ["#counter-ask"] = "反制：你可以令 %src 使用的 %arg 失效！",
}

return skel
